package net.kazed.nextaction.task;

import java.util.List;

import net.kazed.nextaction.database.Task;
import net.kazed.nextaction.database.TaskAttachmentList;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.widget.TextView;

public abstract class AttachmentType {
    
    private int labelResource;
    private int requestCode;

    /**
     * @param labelResource Resource of label string.
     * @param requestCode Unique code for request.
     */
    public AttachmentType(int labelResource, int requestCode) {
        super();
        this.labelResource = labelResource;
        this.requestCode = requestCode;
    }

    /**
     * @return Resource of label string.
     */
    public int getLabelResource() {
        return labelResource;
    }

    /**
     * @return True if intent target is available.
     */
    @SuppressWarnings("unchecked")
    public boolean isIntentTargetAvailable(PackageManager packageManager) {
        List list = packageManager.queryIntentActivities(getIntent(), PackageManager.MATCH_DEFAULT_ONLY);
        boolean available = list.size() > 0;
        return available;
    }
    
    /**
     * @return Intent for attachment type.
     */
    public abstract Intent getIntent();

    /**
     * @return Unique code for request.
     */
    public int getRequestCode() {
        return requestCode;
    }
    
    /**
     * Store attachment to database.
     * @param context Android context.
     * @param contentResolver Content resolver.
     * @param data Returned data.
     * @param attachmentList List of task attachments.
     */
    public abstract void addAttachment(Context context, ContentResolver contentResolver, Intent data, TaskAttachmentList attachmentList);

    /**
     * @param context Android context.
     * @param data Attachment data.
     * @return Link with attachment data.
     */
    public abstract String getAttachmentLink(Context context, Intent data);
    
    /**
     * Add links to view.
     * @param view View that may contain links.
     */
    public abstract void addLinks(TextView view);

}
